%% xr package (beta release)

%% Copyright (C) 1993-1997 David Carlisle

%% This is a modified version of the xr package from the Standard LaTeX
%% tools distribution. It has some internal changes to cooperate with
%% the hyperref package, and one new user level argument, also mainly of
%% use for hyperref.
%% If no problems are reported the version in the tools distribution
%% will be updated to match this at the next LaTeX release.

%% \externaldocument[prefix]{document}[URL]

%% The `document' referred to by the main argument is the file
%% document.aux
%% which must be somewhere on TeX's input path.
%% Some packages (eg hyperref) really need to know the location of the
%% final document rather than the aux file. By default this is assumed
%% to be `document.dvi'. A package may redefine the command \XR@ext to
%% change this default extension (eg some of the hyperref backends
%% define this to be `document.pdf'). However sometimes the final
%% document may be in a position unrelated to the aux file, or the
%% browser may not be able to find files at an arbitrary point in
%% TeX's input path, so the new final optional argument allows a full
%% URL to the final document to be specified.
%%
%% \externaldocument{file}[http://here.xxx.edu/this/path/to/file.dvi]
%%
%% Unless a package redefines \XR@addfile, the optional URL argument
%% will be ignored.
%%
%% This version (beta2) also has another improvement unrelated
%% to the hyperref support. Olivier Michel pointed out that
%% if the aux file was not on texinputs you could not always go
%% \externaldocument{/some/path/to/file}
%% specifically that worked if file.aux was a `simple'  document with
%% one aux file, but if \include had been used, the `sub' aux files
%% would not be found by xr in the remote directory.
%% This version calls \filename@parse to get the directory name of the
%% remote directory, which is then explicitly prepended to the names of
%% any included aux files.
%%
%% History
%%
%% 1997/10/06 v6.00beta2
%%
%% 1999/09/01 v6.00beta3
%%   Definitions of \XR@addURL corrected (Heiko Oberdiek).
%%
%% 2000/03/22 v6.00beta4
%%   \xdef changed to \protected@xdef.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xr-hyper}
         [2000/03/22 v6.00beta4 eXternal References (DPC)]

\def\externaldocument{\@testopt\XR@{}}
\def\XR@[#1]#2{\@testopt{\XR@@{#1}{#2}}{#2.\XR@ext}}

\def\XR@@#1#2[#3]{{%
  \makeatletter
  \def\XR@prefix{#1}%
  \def\XR@URL{#3}%
  \filename@parse{#2}%
  \XR@next#2.aux\relax\\}}
\def\XR@next#1\relax#2\\{%
  \edef\XR@list{#2}%
  \XR@loop{#1}}
\def\XR@aux{%
  \ifx\XR@list\@empty\else\expandafter\XR@explist\fi}

\def\XR@explist{\expandafter\XR@next\XR@list\\}
\def\XR@loop#1{%
\def\f{#1}%\show\f
\openin\@inputcheck#1\relax
  \ifeof\@inputcheck
    \PackageWarning{xr}{^^JNo file #1^^JLABELS NOT IMPORTED.^^J}%
    \expandafter\XR@aux
  \else
    \PackageInfo{xr}{IMPORTING LABELS FROM #1}%
    \expandafter\XR@read\fi}
\def\XR@read{%
  \read\@inputcheck to\XR@line
  \expandafter\XR@test\XR@line...\XR@}
\long\def\XR@test#1#2#3#4\XR@{%
  \ifx#1\newlabel
     \expandafter\protected@xdef\csname r@\XR@prefix#2\endcsname
       {\XR@addURL{#3}}%
  \else\ifx#1\@input
     \edef\XR@list{\XR@list\filename@area#2\relax}%
  \fi\fi
  \ifeof\@inputcheck\expandafter\XR@aux
  \else\expandafter\XR@read\fi}

\providecommand*{\XR@addURL}[1]{#1}
% The above definition doesn't actually use the URL, hyperref 6 could
% make a definition like so to put the URL in the fifth field of its
% ref structure.

\@ifpackageloaded{hyperref}{%
  \PackageWarningNoLine{xr-hyper}{Load package `hyperref' after `xr-hyper'}%
}{}

%\def\XR@addURL#1{\XR@@dURL#1{}{}{}{}\\}

%\def\XR@@dURL#1#2#3#4#5\\{%
%  {#1}{#2}%
%  \if!#4!%
%  \else
%    {#3}{#4}{\XR@URL}%
%  \fi
%}

\providecommand\XR@ext{dvi}

\endinput
%%
%% End of file `xr.sty'.


